enum stopWatchStatus {
  STOPPED,
    RUNNING,
    PAUSED,
};

class cstopWatch {
  cstopWatch(int x, int y, int textSize, color colr) {
    this.x = x;
    this.y = y;
    this.textSize = textSize;
    this.colr = colr;
    reset();
  }

  // put in a 1 second thread to count it
  void counting() {
    if (status == stopWatchStatus.RUNNING) {
      if (++sec >= 60) {
        sec = 0;
        if (++min >= 60) {
          min = 0;
          hr++; // infinited..
        }
      }
    }
  }

  void restart() {
    reset();
    status = stopWatchStatus.RUNNING;
  }

  void reset() {
    hr = 0;
    min = 0;
    sec = 0;
    status = stopWatchStatus.STOPPED;
  }

  void stop() {
    status = stopWatchStatus.STOPPED;
  }

  void pause() {
    status = stopWatchStatus.PAUSED;
  }

  void resume() {
    status = stopWatchStatus.RUNNING;
  }

  void paint() {
    textFont(fontClk); // first action in paint
    textSize(textSize);
    fill(colr);

    String timeStr = str(hr) + ":" + nf(min, 2, 0) + ":" + nf(sec, 2, 0);

    if (status == stopWatchStatus.PAUSED) {
      blk++;
      if (blk < 40) {
        text(timeStr, x, y);
      } else if (blk < 80) {
        // nothing to do
      } else {
        blk = 0;
      }
    } else {
      text(timeStr, x, y);
    }

    // ============== //
    textFont(fontText); // last action in paint
  }

  private int hr, min, sec;
  private stopWatchStatus status; // 0 stopped 1 running 2 paused
  private int blk;
  private int x, y, textSize;
  private color colr;
};

cstopWatch stopWatch = new cstopWatch(710, 130, 80, #7F9527);

void thread1sec() {
  while (true) {
    stopWatch.counting();
    delay(1000);
  }
}
